package file.test;

import com.alibaba.fastjson.JSONObject;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class SwaggerFileParse {

    static List<String> BSList = new ArrayList<String>();
    static List<String> TAList = new ArrayList<String>();

    public static void main(String[] args) {
        readFileLineList();
    }

    public static void readFileLineList() {
        FileInputStream fis = null;
        InputStreamReader isr = null;
        BufferedReader br = null;
        try {
            fis = new FileInputStream("C:\\Users\\LT\\Desktop\\swagger.txt");
            isr = new InputStreamReader(fis);
            br = new BufferedReader(isr);

            String str = br.readLine();

            JSONObject job = JSONObject.parseObject(str);

            JSONObject jobi = job.getJSONObject("paths");

            List<String> result = new ArrayList<>();
            jobi.forEach((key, value) -> {
                JSONObject jobj = (JSONObject) value;

                if (jobj.containsKey("post")) {
                    result.add(key + "	" + jobj.getJSONObject("post").getString("summary"));
                } else {
                    result.add(key + "	" + jobj.getJSONObject("get").getString("summary"));
                }
            });

            result.sort(String::compareTo);
            result.forEach(item -> System.out.println(
                    "insert into `FUNCTION` (`FUNCTIONURL`,`FUNCTIONNAME`)values('" + item.split("	")[0] + "','" + item.split("	")[1] + "');"));

        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
